export const scanMixin = {
  data() {
    return {
      runtimeMainActivity: null,
			receiver: null,
			intentFilter: null,
    };
  },
  methods: {
    registerReceiver() {
    	//  #ifdef APP
    	console.log('initScan:扫码初始化');
    	let that = this;
    	that.runtimeMainActivity = plus.android.runtimeMainActivity(); //获取activity
    	//var context = plus.android.importClass('android.content.Context'); //上下文
    	var IntentFilter = plus.android.importClass('android.content.IntentFilter');
    	that.intentFilter = new IntentFilter();
    	that.intentFilter.addAction("android.intent.action.SCANRESULT");
    	that.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
    		onReceive: (context, intent)=> {
    			plus.android.importClass(intent);
    			let code = intent.getStringExtra("value");
    			that.searchText = code;
    			let obj = {};
    			obj.detail = {};
    			obj.detail.value = code;
    			that.onInput(obj);
    		}
    	});
    	// #endif
    },
    startScan() {
    	//  #ifdef APP
    	this.runtimeMainActivity.registerReceiver(this.receiver, this.intentFilter);
    	// #endif
    },
    stopScan() {
    	//  #ifdef APP
    	this.runtimeMainActivity.unregisterReceiver(this.receiver);
			this.runtimeMainActivity = null;
    	// #endif
    },
  },
};
